import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/28
 */
public class demo1 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 果冻数量
        int[] arr = new int[n+1]; // 美味度
        for (int i = 1; i < n+1; i++) {
            arr[i] = scanner.nextInt();
        }

        int[] max = new int[n+1]; // 最大值
        int[] max2 = new int[n+1]; // 次大值
        max[1] = arr[1];

        for (int i = 2; i <= n; i++) {
            int x = arr[i];
            max[i] = Math.max(max[i-1], x);
            if (x >= max[i-1]) {
                max2[i] = max[i-1];
            } else if (x >= max2[i-1]) {
                max2[i] = x;
            }else {
                max2[i] = max2[i-1];
            }
        }

        int q = scanner.nextInt(); // 询问的次数
        while (q-- != 0) {
            int x = scanner.nextInt();
            System.out.println(max2[x]);
        }

    }
}
